#include "MainWnd.h"
#include <CommCtrl.h>
#include "resource.h"

//---------------------------------------------------------------------------
WWindow::WWindow()
{
	// If we declare a window class with a default constructor,
	// we need to reset the window to a nothing
	_hwnd = NULL;
}
//---------------------------------------------------------------------------
HWND WWindow::Create(HINSTANCE hinst,
    				 LPCTSTR clsname,
	    			 LPCTSTR wndname,
	  	    		 HWND parent,
			    	 DWORD dStyle,
					 DWORD dXStyle,
				     int x,
     				 int y,
	     			 int width,
		    		 int height)
{
	_hInst = hinst;
	// When call the Create() method, we can use it to create a new window
	_hwnd = CreateWindowEx(dXStyle, clsname, wndname, dStyle, x, y, width,
		                 height, parent, NULL, hinst, NULL);
	
	// We hope everything went alright and the window was created
	if( _hwnd != NULL )
		return _hwnd;

	// If something went wrong, for example if the window could not
	// be created, return a "nothing" window
	return NULL;
}
/*
HIMAGELIST g_hImageList = NULL;

HWND WWindow::CreateToolbar( HWND hwnd ) {
	// Declare and initialize local constants.
    const int ImageListID    = 0;
    const int numButtons     = 3;
    const int bitmapSize     = 16;
    
    const DWORD buttonStyles = BTNS_AUTOSIZE;

	INITCOMMONCONTROLSEX commctrl;
	commctrl.dwSize = sizeof(INITCOMMONCONTROLSEX);
	commctrl.dwICC = ICC_BAR_CLASSES;
	InitCommonControlsEx(&commctrl);

    // Create the toolbar.
	HWND hWndToolbar = _hwndTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, 
                                      WS_CHILD | WS_BORDER | WS_VISIBLE, 0, 0, 0, 0, 
                                      hwnd, NULL, GetModuleHandle(NULL), NULL);

    if (hWndToolbar == NULL) {
		MessageBox( _hwnd, L"Error creating toolbar!", L"Draw", MB_OK|MB_ICONERROR );
        return NULL;
	}
    // Create the image list.
    g_hImageList = ImageList_Create(bitmapSize, bitmapSize,   // Dimensions of individual bitmaps.
                                    ILC_COLOR16 | ILC_MASK,   // Ensures transparent background.
                                    numButtons, 0);

    // Set the image list.
    SendMessage(hWndToolbar, TB_SETIMAGELIST, 
                (WPARAM)ImageListID, 
                (LPARAM)g_hImageList);

    // Load the button images.
    SendMessage(hWndToolbar, TB_LOADIMAGES, 
                (WPARAM)IDB_STD_SMALL_COLOR, 
                (LPARAM)HINST_COMMCTRL);

    // Initialize button info.
    // IDM_NEW, IDM_OPEN, and IDM_SAVE are application-defined command constants.
    
    TBBUTTON tbButtons[numButtons] = 
    {
        { MAKELONG(STD_FILENEW,  ImageListID), IDM_NEW,  TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },
        { MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
        { MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0,               buttonStyles, {0}, 0, (INT_PTR)L"Save"}
    };

    // Add buttons.
    SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
    SendMessage(hWndToolbar, TB_ADDBUTTONS,       (WPARAM)numButtons,       (LPARAM)&tbButtons);

    // Resize the toolbar, and then show it.
    SendMessage( hWndToolbar, TB_AUTOSIZE, 0, 0 ); 
    ShowWindow( hWndToolbar,  TRUE );
    
    return hWndToolbar;
}
*/
//---------------------------------------------------------------------------
BOOL WWindow::Show(int dCmdShow)
{
	// We will display the main window as a regular object and update it
	if(	ShowWindow(_hwnd, dCmdShow) && UpdateWindow(_hwnd) ) {
		return TRUE;
	}

	return FALSE;
}
//---------------------------------------------------------------------------
WWindow::operator HWND()
{
	// This overloaded operator allows us to use HWND anyway we want
	return _hwnd;
}
//---------------------------------------------------------------------------
void WWindow::SetText(LPCTSTR strCaption)
{
	SendMessage(_hwnd, WM_SETTEXT, 0, (LPARAM)strCaption);
}
//---------------------------------------------------------------------------
